class Circle(object):
# class object attributes
pi = 3.1415
def __init__(self,radius=1):
self.radius = radius
def area(self):
return self.radius**2 * Circle.pi
def set_radius(self,new_radius):
self.radius = new_radius
def get_radius(self):
return self.radius
pass
In [48]:
class Circle(object):
# class attribute
pi=3.1415
# instance attributes
def __init__(self,radius=1,perimeter=1):
self.radius = radius
self.perimeter = perimeter
# methods
def area(self):
return self.radius**2 * Circle.pi
def setRadius(self,newRadius):
self.radius = newRadius
def getRadius(self):
return self.radius
def getPerimeter(self):
return 2*Circle.pi*self.radius
def setPerimeter(self):
self.perimeter = self.getPerimeter()
pass
c = Circle(radius=123)
In [55]:
c.pi
c.radius
c.area()
c.setRadius(119)
c.radius
c.getRadius()
c.setPerimeter()
In [60]:
c.setRadius(5)
In [61]:
c.getPerimeter()
Out[61]:
In [ ]: